package com.javasm.dao.impl;

import com.javasm.dao.EditMenuDao;
import com.javasm.entity.AdminMenu;
import com.javasm.entity.AdminUser;
import com.javasm.entity.sql.LoginManageSql;
import com.javasm.entity.sql.MenuManageSql;
import com.javasm.util.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * @author WangJie
 * @version 1.0
 * @Description:
 * @date: 2020/7/19 20:32
 * @since JDK 1.8
 */
public class EditMenuDaoImpl implements EditMenuDao {
    /**
     * 新增菜单信息
     *
     * @param adminMenu 要新增的菜单对象
     * @return
     */
    @Override
    public int insertMenuInfo(AdminMenu adminMenu) {
        QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
        int result = 0;
        try {
            result = queryRunner.update(MenuManageSql.INSERT_MENU, adminMenu.getPid(), adminMenu.getPname(),
                    adminMenu.getFid(), adminMenu.getIsshow(), adminMenu.getUrl(), adminMenu.getGlyphicon());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 通过id修改菜单信息
     *
     * @param adminMenu 要修改的菜单对象
     * @return
     */
    @Override
    public int updateMenuInfo(AdminMenu adminMenu) {
        QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
        int result = 0;
        try {
            result = queryRunner.update(MenuManageSql.UPDATE_MENU_BY_PID, adminMenu.getPname(), adminMenu.getFid(),
                    adminMenu.getIsshow(), adminMenu.getUrl(), adminMenu.getGlyphicon(), adminMenu.getPid());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 通过id删除菜单
     *
     * @param pid 要删除的用户id
     * @return
     */
    @Override
    public int deleteMenuInfo(String pid) {
        QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
        int result = 0;
        try {
            result = queryRunner.update(MenuManageSql.DELERE_MENU_BY_PID, pid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
}
